package com.dragon.manage.action;

import com.alibaba.fastjson.JSONObject;
import com.dragon.manage.bean.ManageUser;
import com.dragon.manage.service.IManageService;
import com.dragon.manage.service.IManageUserInfoService;
import com.dragon.manage.util.LogUtil;
import com.dragon.manage.util.ManageUtil;
import com.dragon.manage.util.RightUtil;
import com.dragon.manage.util.StaticData;
import com.dragon.manage.util.StringUtil;
import com.opensymphony.xwork2.ActionContext;
@SuppressWarnings("rawtypes")
public class ManageUserInfoAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	private IManageService manageService;
	
	private IManageUserInfoService manageUserInfoService;
	public IManageService getManageService() {
		return manageService;
	}
	public void setManageService(IManageService manageService) {
		this.manageService = manageService;
	}
	public IManageUserInfoService getManageUserInfoService() {
		return manageUserInfoService;
	}
	public void setManageUserInfoService(
			IManageUserInfoService manageUserInfoService) {
		this.manageUserInfoService = manageUserInfoService;
	}
	/**
	 * 获取用户列表
	 */
	public String getUserInfoList(){
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, 
					request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String pages =request.getParameter("page");
			String types =request.getParameter("type");
			/*
			 * 是否分页
			 */
			int page = StaticData.no_param;
			if(pages!=null&&!pages.isEmpty()){
				page = Integer.parseInt(pages);
			}
			/*
			 * 是否查对应类型
			 */
			int type = StaticData.no_param;
			if(types!=null&&!types.isEmpty()){
				type = Integer.parseInt(types);
			}
			//获取玩家列表
			result =manageUserInfoService.getUserInfoList(type, page);
			
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("获取添加比赛的页面报错",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
	}
	/*
	 * 查看累计充值总额
	 */
	public String checkRecharge(){
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, 
					request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String pages =request.getParameter("page");
			String userIds =request.getParameter("userId");
			String types =request.getParameter("type");
			/*
			 * 是否分页
			 */
			int page = StaticData.no_param;
			if(pages!=null&&!pages.isEmpty()){
				page = Integer.parseInt(pages);
			}
			/*
			 * 是否查对应用户
			 */
			int userId = StaticData.no_param;
			if(userIds!=null&&!userIds.isEmpty()){
				userId = Integer.parseInt(userIds);
			}
			
			int type = StaticData.getDataType.cache.getType();
			if(types!=null&&!types.isEmpty()){
				type = Integer.parseInt(types);
			}
			result = manageUserInfoService.checkRecharge(userId, page,type);
			
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("查看累计充值总额",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
	}
	/**
	 * 查看用户亏盈
	 */
	public String userProfitTotal(){
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, 
					request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String userIds =request.getParameter("userId");
			String types =request.getParameter("type");
			/*
			 * 是否查对应用户
			 */
			int userId = StaticData.no_param;
			if(userIds!=null&&!userIds.isEmpty()){
				userId = Integer.parseInt(userIds);
			}
			
			int type = StaticData.getDataType.cache.getType();
			if(types!=null&&!types.isEmpty()){
				type = Integer.parseInt(types);
			}
			result = manageUserInfoService.userProfitTotal(userId, type);
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("获取添加比赛的页面报错",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
	}
	/**
	 * 竞猜明细
	 */
	public String userBetDetail(){
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, 
					request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String pages =request.getParameter("page");
			String userIds =request.getParameter("userId");
			if(userIds==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			/*
			 * 是否分页
			 */
			int page = StaticData.no_param;
			if(pages!=null&&!pages.isEmpty()){
				page = Integer.parseInt(pages);
			}
			
			result = manageUserInfoService.userBetDetail(StringUtil.getParam(userIds), page);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("竞猜明细",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
	}
	
	/**
	 * 竞猜明细
	 */
	public String userExchangeList(){
		ActionContext ct=ActionContext.getContext();
		JSONObject result = new JSONObject();
		try {
			/*
			 * 再通过sessionid获取用户信息
			 */
			ManageUser manageUser =  ManageUtil.getManageUserBySession(ct, result, 
					request,manageService, RightUtil.getRightId(this.getClass().getName()));
			if(manageUser==null){
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			String pages =request.getParameter("page");
			String userIds =request.getParameter("userId");
			if(userIds==null){
				result.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
				ct.put(StaticData.reKey.result.getKey(), result);
				return StaticData.RE_SUCCESS;
			}
			
			result = manageUserInfoService.userExchangeList(StringUtil.getParam(userIds)
					,StringUtil.getParam(pages) );
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		} catch (Exception e) {
			LogUtil.error("获取添加比赛的页面报错",e);
			result.put(StaticData.reKey.code.getKey(), StaticData.codeType.other_error.getType());
			ct.put(StaticData.reKey.result.getKey(), result);
			return StaticData.RE_SUCCESS;
		}
	}
}
